{{ if and .Site.Params.imageGallery .Params.gallery }}
  {{ $galleryLength := len .Params.gallery }}
  {{ $imageGalleryClass := "" }}
  {{ if gt $galleryLength 0 }}
    <div class="image-gallery">
      <div class="image-gallery-metabar">
        <span>Gallery {{ $galleryLength }} images</span>
      </div>
      <div class="image-gallery-photos {{ if gt $galleryLength 2 }}image-gallery-photos--thumbnail{{ end }}">
        {{ range $index, $element := .Params.gallery }}
          {{ $image := (split $element " ") }}
          {{ $imageLength := len $image }}
          <div class="photo-box">
            <a class="photo-box-inner fancybox" data-fancybox-group="gallery-{{ $.File.UniqueID }}"
               title="{{ if gt $imageLength 2 }}{{ index $image 2 }}{{ else }}{{ index $image 1 }}{{ end }}" href="{{ index $image 0 }}">
              <img class="photo" src="{{ if gt $imageLength 2 }}{{ index $image 1 }}{{ else }}{{ index $image 0 }}{{ end }}" itemprop="image">
            </a>
          </div>
        {{ end }}
      </div>
    </div>
    {{ end }}
{{ end }}